feat: Derive fiat order sourceAmount from on-chain tx data and persist fiat order metadata#8694
Merged
Merged
Conversation
…toAmount fallback
sourceAmount from on-chain tx data
sourceAmount from on-chain tx data
matthewwalsh0
requested changes
May 12, 2026
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit bf1e13a. Configure here.
matthewwalsh0
previously approved these changes
May 12, 2026
matthewwalsh0
approved these changes
May 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Explanation
1. Derive fiat order
sourceAmountfrom on-chain tx dataCurrently, the fiat submit flow derives
sourceAmountRawfromorder.cryptoAmount- a human-readable value reported by the on-ramp provider. This value may not precisely reflect what was actually received on-chain.This PR reads the actual transferred amount from the completed on-chain transaction (
order.txHash) instead. For native tokens, the amount is taken fromtx.value. For ERC-20 tokens, the amount is decoded from thetransfer(address,uint256)call data. If the on-chain read fails or the transaction hash is missing, the existingorder.cryptoAmountderivation is used as a fallback.The implementation introduces:
getTransferredAmountFromTxHash- a generic utility inutils/transaction-receipt.tsthat reads transferred amounts from any on-chain transaction (native or ERC-20). Takes explicitchainIdandtokenAddressparams for reusability.resolveSourceAmountRaw- a fiat-strategy-specific function instrategy/fiat/utils.tsthat orchestrates the on-chain read withorder.cryptoAmountfallback.getRawSourceAmountFromOrderCryptoAmount- the existing decimal-shift conversion, moved fromfiat-submit.tstostrategy/fiat/utils.tsand renamed for clarity.2. Persist fiat order metadata on
metamaskPayThe
TransactionPayControllerstate is cleaned up when a transaction is finalized (confirmed/failed/dropped). This meansfiatPayment.orderIdand the provider info are gone by the time the user opens the activity/transaction-details view.To enable the mobile activity view to show a fiat order status row (and query
RampsController:getOrderfor live status), this PR persists the fiat order ID and provider code ontransaction.metamaskPaybefore polling begins insubmitFiatQuotes.Changes:
MetamaskPayMetadata(transaction-controller/types.ts) — AddedfiatOrderId?: stringandfiatProvider?: stringfields.submitFiatQuotes(fiat-submit.ts) — CallsupdateTransactionto persistfiatOrderIdandfiatProviderontx.metamaskPaybeforewaitForOrderCompletionstarts polling. This ensures data is available even while the order is still in-flight.metamaskPayfields are preserved.References
FiatStrategysubmit flow with order polling and relay execution #8347Checklist
Note
Medium Risk
Updates fiat on-ramp submission to depend on on-chain receipt/trace parsing and persists new metadata onto
TransactionMeta, which could affect payment execution and activity display if RPC methods/log parsing behave unexpectedly across networks.Overview
Fiat on-ramp submit flow now persists order identifiers onto
transaction.metamaskPay.fiat(order ID + provider code) before polling, so downstream activity views can query order status even after controller state cleanup.The relay leg’s
sourceAmountRawis now derived from the actual on-chain transfer referenced byorder.txHashvia new utilities that parse ERC-20Transferlogs or native transfers (usingdebug_traceTransactionwith atx.valuefallback), falling back toorder.cryptoAmountconversion when on-chain reads are unavailable.Adds
MetamaskPayMetadata.fiatto the transaction-controller types and updates/extends unit tests around fiat submission, amount resolution, and receipt/trace parsing.Reviewed by Cursor Bugbot for commit 46177a2. Bugbot is set up for automated code reviews on this repo. Configure here.